<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>移库管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
        function c(v){
            $.ajax({
                cache : true,
                type : "POST",
                url: "${ctx}/stock/containerDetail/alllist",
                data : {
                    "w.c.id":v
                },
                async : false,
                success : function(data) {
                    console.log(data);
                    for (var i=0; i<data.length; i++){
                        data[i].c=data[i].w;
                        data[i].name="";
                        data[i].w.id=data[i].id;
                        addRow('#moveStockDetailList', moveStockDetailRowIdx, moveStockDetailTpl, data[i]);
                        moveStockDetailRowIdx = moveStockDetailRowIdx + 1;
                    }

                }
            });

        }
		function addRow(list, idx, tpl, row){
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			$(list+idx).find("input[type='checkbox'], input[type='radio']").each(function(){
				var ss = $(this).attr("data-value").split(',');
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
		}
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}else if(delFlag.val() == "0"){
				delFlag.val("1");
				$(obj).html("&divide;").attr("title", "撤销删除");
				$(obj).parent().parent().addClass("error");
			}else if(delFlag.val() == "1"){
				delFlag.val("0");
				$(obj).html("&times;").attr("title", "删除");
				$(obj).parent().parent().removeClass("error");
			}
		}
	</script>
</head>
<body>
	 移库审批<br/>
	<form:form id="inputForm" modelAttribute="moveStock" action="${ctx}/stock/moveStock/saveAudit" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>
		<form:hidden path="act.taskId"/>
		<form:hidden path="act.taskName"/>
		<form:hidden path="act.taskDefKey"/>
		<form:hidden path="act.procInsId"/>
		<form:hidden path="act.procDefId"/>
		<form:hidden id="flag" path="act.flag"/>
		<div class="control-group">
			<label class="control-label">用户：</label>
			<div class="controls">
			 	<form:input path="user.name" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>

			</div>
		</div>

		<div class="control-group">
			<label class="control-label">源仓库：</label>
			<div class="controls">
				<form:input path="locid.name" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>

			</div>
		</div>
		<div class="control-group">
			<label class="control-label">目标仓库：</label>
			<div class="controls">
				<form:input path="tlocid.name" htmlEscape="false" maxlength="255" class="input-xlarge " readonly="true"/>

			</div>
		</div>
			<div class="control-group">
				<label class="control-label">移库名称：</label>
				<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>托盘</th>
								<th>数量</th>
								<th>目标托盘</th>
							</tr>
						</thead>
						<tbody id="moveStockDetailList">
						</tbody>

					</table>
					<script type="text/template" id="moveStockDetailTpl">//<!--
						<tr id="moveStockDetailList{{idx}}">
							<td class="hide">
								<input id="moveStockDetailList{{idx}}_id" name="moveStockDetailList[{{idx}}].id" type="hidden" value="{{row.id}}"/>
								<input id="moveStockDetailList{{idx}}_delFlag" name="moveStockDetailList[{{idx}}].delFlag" type="hidden" value="0"/>
									<input   name="moveStockDetailList[{{idx}}].w.id" type="hidden" value="{{row.w.id}}"/>
							</td>

							<td>
								<input id="moveStockDetailList{{idx}}_w" readonly name="moveStockDetailList[{{idx}}].w.c.name"   type="text" value="{{row.w.c.name}}" maxlength="32" class="input-small "/>
							</td>
							<td>
								<input id="moveStockDetailList{{idx}}_name" readonly name="moveStockDetailList[{{idx}}].name" type="text" value="{{row.name}}" maxlength="255" class="input-small required"/>
							</td>
							<td>
							<select name="outOrderDetailList[{{idx}}].t.id" id="outOrderDetailList{{idx}}_t" data-value="{{row.t.id}}" class="input-small required">
							        <c:forEach items="${cs}" var="w">
										<option value="${w.id}">${w.name}</option>
									</c:forEach>
							</select>
							</td>

						</tr>//-->
					</script>
					<script type="text/javascript">
						var moveStockDetailRowIdx = 0, moveStockDetailTpl = $("#moveStockDetailTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(moveStock.moveStockDetailList)};
							for (var i=0; i<data.length; i++){
								addRow('#moveStockDetailList', moveStockDetailRowIdx, moveStockDetailTpl, data[i]);
								moveStockDetailRowIdx = moveStockDetailRowIdx + 1;
							}
						});
					</script>
				</div>
			</div>
		<div class="control-group">
			<label class="control-label">您的意见：</label>
			<div class="controls">
				<form:textarea path="act.comment" class="required" rows="5" maxlength="20" cssStyle="width:500px"/>
			</div>
		</div>
		<div class="form-actions">
				<input  class="btn btn-primary" type="submit" value="同 意" onclick="$('#flag').val('yes')"/>&nbsp;
				<input   class="btn btn-inverse" type="submit" value="驳 回" onclick="$('#flag').val('no')"/>&nbsp;
			<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
		</div>
	</form:form>
</body>
</html>